package jy_redis

import(
	"context"
	"github.com/go-redis/redis/v8"
	Config "jy_go/config"
	"jy_go/jy_log"
)

var (
	Redis *redis.Client
	localhost 	= Config.Config("config","redis","localhost")
	port		= Config.Config("config","redis","port")
	Password	= Config.Config("config","redis","password")
)


var ctx = context.Background()

//连接redis
func GetRedis() *redis.Client {
	rdb := redis.NewClient(&redis.Options{
		Addr:     localhost + ":" + port,
		Password: Password, // no password set
		DB:       0,  // use default DB
	})
	err := rdb.Ping(ctx).Err()
	if err != nil {
		go jy_log.JyLog("redis连接失败，err:" + err.Error())
		panic("redis连接失败，err：" + err.Error())
	}
	Redis = rdb
	return Redis
}
